var webpack = require('webpack');

var AssetsPlugin = require('assets-webpack-plugin');

var baseConfigInit = require('./webpack.base.config');

var CleanWebpackPlugin = require('clean-webpack-plugin');

var baseConfig = baseConfigInit("PROD");

var fs = require("fs");

var process = require("process");

const rootPath = process.cwd();

var prodConfig = {
    plugins:[
        new webpack.optimize.OccurrenceOrderPlugin(true),
        //js压缩参数
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
                drop_console: true
            },
            beautify:false,
            comments:false
        }),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: '"production"'
            }
        }),
        new webpack.LoaderOptionsPlugin({
            minimize: true
        }),
        new AssetsPlugin({
            filename:"asset-map.json",
            processOutput:function ( assets ) {
                var common = assets.common;
                var page   = {};
                for(var key in assets) {
                    if(key!=="common") {
                        page[key]={
                            css:[
                                common.css,
                                assets[key].css
                            ],
                            js:[
                                common.js,
                                assets[key].js
                            ]
                        }
                    }
                };
                return JSON.stringify(page);
            }
        }),
        new CleanWebpackPlugin(
            "dist",　 //匹配删除的文件
            {
                root: __dirname,       　　　　　　　　　　//根目录
                verbose:  true,        　　　　　　　　　　//开启在控制台输出信息
                dry:      false        　　　　　　　　　　//启用删除文件
            }
        )
    ]
};

baseConfig.output.publicPath = "http://cnode.static.yutao2012.com/";

baseConfig.plugins = prodConfig.plugins.concat( baseConfig.plugins );

module.exports = baseConfig;